﻿using System;
using System.Windows.Input;

namespace DCT.ViewModel
{
    public abstract class WorkspaceViewModel : ViewModelBase
    {
        #region Fields

        string _displayName;
        bool _isActivated;
        bool _isChanged;

        #endregion // Fields

        #region Properties

        public bool IsChanged
        {
            get
            {
                return _isChanged;
            }
            set
            {
                if (value != _isChanged)
                {
                    _isChanged = value;
                    base.OnPropertyChanged("IsChanged");
                }
            }
        }

        public string DisplayName
        {
            get
            {
                return _displayName;
            }
            set
            {
                if (value != _displayName)
                {
                    _displayName = value;
                    base.OnPropertyChanged("DisplayName");
                }
            }
        }

        public bool IsActivated
        {
            get 
            { 
                return _isActivated; 
            }
            set
            {
                if (value != _isActivated)
                {
                    _isActivated = value;
                    base.OnPropertyChanged("IsActivated");
                }
            }
        }

        #endregion // Properties

        #region Commands

        #region CloseCommand

        public bool Close_Can()
        {
            return WorkspaceManager.Instance.Contains(this);
        }

        public void Close_Execute()
        {
            WorkspaceManager.Instance.Close(this);
        }

        RelayCommand _closeCommand;
        public ICommand CloseCommand
        {
            get
            {
                if (_closeCommand == null)
                    _closeCommand = new RelayCommand(param => this.Close_Execute());

                return _closeCommand;
            }
        }

        #endregion // CloseCommand

        #region Show Command

        public void Show_Execute()
        {
            WorkspaceManager.Instance.ActiveWorkspace = this;
        }

        public bool Show_Can()
        {
            return true;
        }

        RelayCommand _showCommand;
        public ICommand ShowCommand
        {
            get
            {
                if (_showCommand == null)
                    _showCommand = new RelayCommand(param => this.Show_Execute(),
                                                    param => this.Show_Can());

                return _showCommand;
            }
        }

        #endregion

        #endregion // Commands

        #region Methods

        internal virtual void Activated()
        {
            this.IsActivated = true;
        }

        internal virtual void UnActivated()
        {
            this.IsActivated = false;
        }

        #endregion // Methods
    }
}